package com.falcon.system.domain.request;

import com.falcon.core.domain.AbsPageQuery;
import com.falcon.system.domain.po.SystemLogPO;
import com.swan.mybatis.condition.Condition;
import com.swan.mybatis.condition.OpType;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Date;
import java.util.List;
import java.util.Objects;


/** 用户表
* @author zongf
* @since 2024-03-19
*/
@Data
@Accessors(chain = true)
public class SystemLogQuery extends AbsPageQuery {

    /** 创建者id */
    private String logId;

    /** 开始时间 */
    private Date startTime;

    /** 开始时间 */
    private Date endTime;

    /** 类名 */
    private String className;

    /** 类名 */
    private String methodName;

    /** 关键字列表 */
    private List<String> keywords;

    /** 日志级别 */
    private List<String> levels;

    @Override
    public Condition toCondition() {
        Condition condition = Condition.newInstance();
        condition.ignoreEmptyString();
        condition.and(SystemLogPO.Fields.logId, OpType.equals, this.logId);
        condition.and(SystemLogPO.Fields.logTime, OpType.greaterOrEquals, this.startTime);
        condition.and(SystemLogPO.Fields.logTime, OpType.lessThan, this.endTime);
        condition.and(SystemLogPO.Fields.className, OpType.like, this.className);
        condition.and(SystemLogPO.Fields.methodName, OpType.like, this.methodName);
        condition.and(SystemLogPO.Fields.level, OpType.in, this.levels);
        if (Objects.nonNull(keywords)) {
            for (String keyword : keywords) {
                condition.and(SystemLogPO.Fields.message, OpType.like, keyword);
            }
        }
        return condition;
    }

}
